package org.objective.base;

import org.common.container.Container;
import org.common.service.ServiceRegister;
import org.common.treebuilder.TreeContainer;
import org.graph.base.Node;

/**
 *
 * @author gus
 */
public class MetaDataContainer
{
    private final ServiceRegister register;
    public final TreeContainer<Node<Long, CommonObject<? extends DomainObject>>, CommonObject<? extends DomainObject>> container;
    public final Storage storage;
    private static MetaDataContainer metaDataContainer = null;

    public synchronized static MetaDataContainer getInstance(ServiceRegister register) throws Exception
    {
        if (metaDataContainer == null)
        {
            metaDataContainer = new MetaDataContainer(register);
        }
        return metaDataContainer;
    }

    public synchronized static MetaDataContainer getInitializedContainer() throws Exception
    {
        if (metaDataContainer == null)
        {
            throw new Exception("not initialized container");
        }
        return metaDataContainer;
    }

    protected MetaDataContainer(ServiceRegister register) throws Exception
    {
        this.register = register;
        this.storage = StorageFactory.getDefaultStorage(register);
        this.container = new Container();
    }

    public void rebuildContainer() throws Exception
    {
        container.flush();
    }

    public void loadMetaData() throws Exception
    {
        storage.loadMetaData();
    }
}
